//
//  MeTopCell.swift
//  SwitfTest
//
//  Created by runone02 on 2019/1/9.
//  Copyright © 2019年 liqiyun. All rights reserved.
//

import UIKit
import Photos

class MeTopCell: UITableViewCell {
    // 如果是单独访问相机，一定要声明为全局变量
    let imagePickTool = CLImagePickerTool()
    /// 头像
    var icon : UIImageView!
    /// 用户名
    var nameLabel : UILabel!
    /// 账号
    var accountLabel : UILabel!
    /// 二维码
    var RQcodeImage : UIImageView!
    /// 下一级图标
    var arrowImage : UIImageView!
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle(rawValue: 0)!
        self.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        self.setUpUI()
    }
    
    ///选择头像
    @objc func iconClick(){
        imagePickTool.cameraOut = true
       
        imagePickTool.cl_setupImagePickerWith(MaxImagesCount: 1) { (asset,cutImage) in
            //返回照片z设置
            CLImagePickerTool.convertAssetArrToOriginImage(assetArr: asset, scale: 0.1, successClouse: {[weak self] (image,assetItem) in
                self?.icon.image = image

                }, failedClouse: { () in

            })
        }
    }
    
    func setUpUI() {
        icon = UIImageView()
        icon.backgroundColor = UIColor.black
        icon.contentMode = .scaleAspectFill

        icon.layer.masksToBounds = true
        icon.layer.cornerRadius = 40
        icon.layer.borderWidth = 1.0
        icon.layer.borderColor = UIColor.white.cgColor

        let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(iconClick))
        icon?.addGestureRecognizer(singleTapGesture)
        icon?.isUserInteractionEnabled = true

        self.addSubview(icon)
        icon.mas_makeConstraints { (make) in
            make?.centerY.mas_equalTo()(self)
            make?.left.mas_equalTo()(10)
            make?.width.mas_equalTo()(80)
            make?.height.mas_equalTo()(80)
        }
        
        nameLabel = UILabel()
        nameLabel.textColor = UIColor.black
        nameLabel.text = "y用户名"
        nameLabel.font = UIFont.systemFont(ofSize: 15)
        self.addSubview(nameLabel)
        nameLabel.mas_makeConstraints { (make) in
            make?.top.mas_equalTo()(icon)
            make?.left.mas_equalTo()(icon.mas_right)?.offset()(10)
        }
        
        accountLabel = UILabel()
        accountLabel.text = "账号"
        accountLabel.textColor = UIColor.black
        accountLabel.font = UIFont.systemFont(ofSize: 15)
        self.addSubview(accountLabel)
        accountLabel.mas_makeConstraints { (make) in
            make?.bottom.mas_equalTo()(icon)
            make?.left.mas_equalTo()(icon.mas_right)?.offset()(10)
        }
        
        
        arrowImage = UIImageView()
        arrowImage.backgroundColor = UIColor.blue
        self.addSubview(arrowImage)
        arrowImage.mas_makeConstraints { (make) in
            make?.centerY.mas_equalTo()(self)
            make?.right.mas_equalTo()(self)?.offset()(-10)
            make?.width.mas_equalTo()(20)
            make?.height.mas_equalTo()(20)
        }
        
        RQcodeImage = UIImageView()
        RQcodeImage.backgroundColor = UIColor.red
        self.addSubview(RQcodeImage)
        RQcodeImage.mas_makeConstraints { (make) in
            make?.centerY.mas_equalTo()(arrowImage)
            make?.right.mas_equalTo()(arrowImage.mas_left)?.offset()(-10)
            make?.width.mas_equalTo()(20)
            make?.height.mas_equalTo()(20)
        }
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
